/** \file    imagine.cpp
  * \brief   Representation functions of different 2d objects
  * \date    2001
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/imglib/src/imagine.cpp,v 1.1 2004/02/04 14:43:23 cscom1r4 Exp $
  */

#include "imglib/imagine.h"
#include "imglib/imageclass.h"

namespace img {

void emphasizeMask(byte_image &img, const img::bitmap &bmp, bool blend, const byte_color &color)
{
	int w = img.width();
	int h = img.height();
	for( int y = 0; y != h; ++y ) {
		for( int x = 0; x != w; ++x ) {
			if (bmp(x,y)) 
				continue;
			byte_color &p = img(x,y);
			if (!blend) {
				p = color;
				continue;
			}
			p.r = (color.r + p.r) / 2;
			p.g = (color.g + p.g) / 2;
			p.b = (color.b + p.b) / 2;
			p.a = (color.a + p.a) / 2;
		}
	}
}

void emphasizeMask(byte_image &img, bool blend, const byte_color &color)
{
	int w = img.width();
	int h = img.height();
	img::BGRA<unsigned int> a1, a2;

	for( int y = 0; y != h; ++y ) {
		for( int x = 0; x != w; ++x ) {
			byte_color & i = img(x,y);
			unsigned char a = i.a;
			a1 = i;
			a2 = color;
			if (blend) {
				a1 *= 255 + a; //255 --- 510
				a2 *= 255 - a; //  0 --- 255
				i = (a1 + a2) / 510;
			} else {
				a1 *= a;
				a2 *= 255 - a;
				i = (a1 + a2) / 255;
			}
			i.a = a;
		}
	}
}

} //namespace img
